
%   Example script for running MCS

%   Written by Sean Walton (512465@swansea.ac.uk) 2011 for Swansea
%   university

%   Please cite the following paper when using this code...
%   S.Walton, O.Hassan, K.Morgan and M.R.Brown "Modified cuckoo search: A
%   new gradient free optimisation algorithm" Chaos, Solitons & Fractals Vol
%   44 Issue 9, Sept 2011 pp. 710-718 DOI:10.1016/j.chaos.2011.06.004


%   I'd appreciate it if you contacted me (512465@swansea.ac.uk) if you apply the code to a
%   problem succesfully, I'm always interested in hearing about new applications 


%The structure S contains all the parameters for the MCS
S.pa = 0.7;
S.plot = 0;         %If you want the results plotted set this to 1
S.constrain = 1;    %Set to 1 if you want the search constrained within vardef, zero otherwise
S.A = 10; %   Maximum distance a cuckoo can travel in one step as fraction of search space diagonal
S.pwr = 0.5;
S.flight = 1;
S.NesD = 1;

if(S.bioheat==1)                               %define objective function
    S.fname ='bioheat_obj';
elseif(S.bioheat==0)
    S.fname = 'simulated_obj';
end

if(S.bioheat==0)                               %define constraints 
    if(S.needle_num==2)
        n_x    = 10;                           % 'n_x' state
        Data.xlow = [S.minX S.minY S.minZ S.minX S.minY S.minZ 0 0 0 0];
        Data.xup = [S.maxX S.maxY S.maxZ S.maxX S.maxY S.maxZ 180 180 180 180];
    elseif(S.needle_num==3)
        n_x  = 15;
        Data.xlow = [S.minX S.minY S.minZ S.minX S.minY S.minZ 0 0 0 0 S.minX S.minY S.minZ 0 0];
        Data.xup = [S.maxX S.maxY S.maxZ S.maxX S.maxY S.maxZ 180 180 180 180 S.maxX S.maxY S.maxZ 180 180];
    end
end

if(S.bioheat==1)
        Data.xlow=[S.boundx+S.b S.boundy+S.b S.boundz+S.b 0 0]; 
        Data.xup=[ max(S.x)-min(S.x)+S.boundx-S.b  max(S.y)-min(S.y)+S.boundy-S.b  max(S.z)-min(S.z)+S.boundz-S.b 180 180];
        if(S.needle_num==2)
            n_x    = 10;                           % 'n_x' state
            Data.xlow = [Data.xlow Data.xlow];
            Data.xup = [Data.xup Data.xup];
        elseif(S.needle_num==3)
            n_x  = 15;
            Data.xlow = [Data.xlow Data.xlow Data.xlow];
            Data.xup = [Data.xup Data.xup Data.xup];
        elseif(S.needle_num==4)
            n_x  = 20;
            Data.xlow = [Data.xlow Data.xlow Data.xlow Data.xlow];
            Data.xup = [Data.xup Data.xup Data.xup Data.xup];
        elseif(S.needle_num==5)
            n_x  = 25;
            Data.xlow = [Data.xlow Data.xlow Data.xlow Data.xlow Data.xlow];
            Data.xup = [Data.xup Data.xup Data.xup Data.xup Data.xup];
        end
end

%The matrix vardef defines the upper and lower bounds of the initial set of
%nests, the MCS uses this to set boundaries on the plots and LHC uses it to
%generate initial eggs

NoDim =n_x;

vardef(2,1:NoDim) = Data.xlow;
vardef(1,1:NoDim) = Data.xup;

NoNests = 10;

NestI = LHC(vardef,NoNests); %Generates initial set of eggs

NoGen = S.runs;

%Run optimiser
[p,F,pg,numEval,diversity] = ACuckoov3(NoGen, NestI, S, vardef);

%The optimum position is then pg

